package org.example.java.base;

/**
 * Created by Juntao.Zhang on 2014/10/7.
 */
public class ShutdownHookTest {
  static class MyFlag {
    MyFlag(String flag) {
      this.flag = flag;
    }

    public String flag = "";

    @Override
    public String toString() {
      return "MyFlag{" +
          "flag='" + flag + '\'' +
          '}';
    }
  }

  public static void main(String[] args) {
    final MyFlag flag = new MyFlag("running");
    System.out.println("running...");
    Runtime.getRuntime().addShutdownHook(new Thread("test") {
      @Override
      public void run() {
        flag.flag = "stop";
        System.out.println("show down -> " + flag);
        System.out.println("shut down");
      }
    });
    System.out.println("main -> " + flag);
    System.out.println("main finish");
  }
}
